package com.happe.foodeasy.manage.service.impl;

import com.happe.foodeasy.manage.dao.PositionImageMapper;
import com.happe.foodeasy.manage.dto.PositionImageDTO;
import com.happe.foodeasy.manage.service.PositionImageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("positionImageService")
public class PositionImageServiceImpl implements PositionImageService {
    @Resource
    private PositionImageMapper positionImageMapper;

    @Override
    public void storePositionImage(PositionImageDTO positionImageDTO) {
        positionImageMapper.storePositionImage(positionImageDTO);
    }

    @Override
    public List<PositionImageDTO> selectByPositionAndStatus(long position, long status) {
        PositionImageDTO param = new PositionImageDTO();
        param.setImagePositionId(position);
        param.setLinkImageStatusId(status);
        return positionImageMapper.selectByParam(param);
    }

    @Override
    public PositionImageDTO selectById(long imageId) {
        PositionImageDTO param = new PositionImageDTO();
        param.setId(imageId);
        List<PositionImageDTO> result = positionImageMapper.selectByParam(param);
        if (result.size() != 1) {
            throw new RuntimeException("根据位置图片的单个id查找到不止一个位置图片");
        }
        return result.get(0);
    }

    @Override
    public PositionImageDTO selectTargetByteById(long imageId) {
        return positionImageMapper.selectTargetByteById(imageId);
    }
}
